<template>
	<view class="content">
		<view class="menu-block">
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view class="must" style="color: #EA0000;">*</view>
					<view class="form-label">评分</view>
				</view>
				<view class="score" style="margin: 40rpx 0;">
					<uni-rate v-model="form.rateValue" @change="onChange" :readonly="false"  active-color="red" :size="22"/>
				</view>
			</view>
			<view class="form-item" style="border-bottom: none;">
				<view style="display: flex;flex-direction: row;">
					<view class="form-label">评论</view>
				</view>
				<view class="form-content" style="margin: 40rpx 0;">
					<textarea v-model="form.content" placeholder="请简述你的评价" class="info-crl"
						maxlength="300"></textarea>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
		</view>
		<view class="step" @click="handleSave">
			提交
		</view>
	</view>
</template>

<script>
	import {
		userAddComment
	} from '@/api/teacher.js';
	import {
		validate
	} from '@/util/validate.js'
	export default {
		data() {
			return {
				form: {
					score: '',
					content: '',
					relationId:null,
					type:null,
				},
				type:1,
				rules: {
					score: {
						name: '评分',
						required: true
					},
					content: {
						name: '你的评价',
						required: true
					},
				},
				id: null,
			}
		},
		methods: {
			onChange(e){
				this.form.score = e.value
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			handleSave() {
				let form = JSON.parse(JSON.stringify(this.form));
				form.score = this.form.score
				form.content = this.form.content
				form.type = this.form.type
				form.relationId = this.form.relationId
				if (validate(form, this.rules)) {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					userAddComment(form).then((res) => {
						uni.hideLoading()
						this.showToast(res, () => {
							this.navigate('/page_other/submit/submit')
						})
					}).catch((res) => {
						uni.hideLoading()
						this.showToast('提交失败');
					})
				}
			}

		},
		onLoad(e) {
			//培训机构ID
			this.form.relationId = e.id
			this.form.type = e.type
		},
		onReachBottom() {
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fafafa;
	}
	.content {
		width: 100%;
		padding: 30rpx;
		.step{
			width: 350rpx;
			height: 100rpx;
			display: flex;
			background-color: red;
			color: #fff;
			margin: 30rpx auto;
			border-radius: 60rpx;
			justify-content: center;
			align-items: center;
		}
		.menu-block {
			margin-top: 30rpx;
			background: #fff;
			border-radius: 12px;
			padding: 30rpx;
			
			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;
			
				.form-label {
					font-size: 32rpx;
					color: #1A1A1A;
				}
			
				.form-content {
					display: flex;
					flex-direction: column;
					// align-items: center;
			
					.arrow {
						flex-grow: 0;
						color: #767676;
						font-size: 32rpx;
					}
				}
			}
		}
	}
</style>